<%-- 
/*
Assignment 1
Class ID        : SE0691
Group           : 1
Due Date        : 20 November 2012
I declare that this assignment is my own work
in accordance with FPT Policy.
*/
--%>

<%@page import="edu.fpt.dal.RequestServicesDAL"%>
<%@page import="edu.fpt.hib.RequestServices"%>
<%@page import="edu.fpt.dal.ServicesDAL"%>
<%@page import="edu.fpt.hib.Services"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="edu.fpt.dal.ApartmentDAL"%>
<%@page import="edu.fpt.hib.Apartment"%>
<%@page import="edu.fpt.dal.UsersDAL"%>
<%@page import="edu.fpt.hib.Users"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>My Services</title>
        <style type="text/css"> <!--@import url("../style.css");--></style>
        <script>function goBack()  {  window.history.back()  }</script>
    </head>
    <body>
        <%@include file="template/header.jsp" %>
        <%try {
                Users users = UsersDAL.getUsersHQL(session.getAttribute("currentUser").toString());
                Apartment apart = ApartmentDAL.getApartmentByUserHQL(session.getAttribute("currentUser").toString());
                StringTokenizer stToken = new StringTokenizer(apart.getUsingServices(), " ");
                ArrayList<String> ser = new ArrayList<String>();
                ArrayList<RequestServices> listReq = RequestServicesDAL.listByUser(users.getUserId());
                while (stToken.hasMoreElements()) {
                    ser.add(stToken.nextToken().toString());
                }
        %>
        <div id="page">
            <table style="width: 950px;">
                <tr>
                    <td style="float: left;"><form method="post" action="registerservices.jsp">
                            <input class="searchsubmit" type="submit" name="Submit" value="Registering for using services">
                        </form></td>
                </tr>
            </table>
            <hr>
            <div class="post">
                <h3 class="title">Using Services</h3>
                <table><% for (int i = 0; i < ser.size(); i++) {
                        Services services = ServicesDAL.getByServicesID(ser.get(i));
                        if(services!=null){
                %>
                    <tr><td><%=services.getServiceName()%></td><td style="text-align: right;"><%=services.getServicePrice()%></td>
                        <td><form method="get" action="deleteservice.jsp">
                                <input type="hidden" name="serviceid" value="<%=services.getServiceId()%>">
                                <input class="searchsubmit" type="submit" value="Stop using this service">
                            </form></td></tr>
                    <%}}%></table>
                <h3 class="title">Pending Services</h3>
                <table><% for (int i = 0; i < listReq.size(); i++) {
                        Services services = ServicesDAL.getByServicesID(listReq.get(i).getServices().getServiceId());%>
                    <tr><td><%=services.getServiceName()%></td><td style="text-align: right;"><%=services.getServicePrice()%></td><td><%=listReq.get(i).getRequestStatus()%> </td></tr>
                    <%}
                        } catch (Exception e) {
                            out.println(e.getMessage());
                        }%></table>
            </div>
        </div>
        <%@include file="template/footer.jsp" %>
    </body>
</html>
